/**
 *
 * @author 
 *
 */
class CardIndex {
    public constructor() {
    }
    public static baiIndex: number = 1;
    public static shiwanIndex: number = 2;
    public static yiwanIndex: number = 3;
    public static yiqianwanIndex: number = 4;
    public static yiqianIndex: number = 5;
    public static yibaiwanIndex: number = 6;
    public static wubaiwanIndex: number = 7;
}
class ToolUtils {
    public constructor() {
    }
    public static setGray(btm: egret.Bitmap) {
        //颜色矩阵数组
        var colorMatrix = [
            0.3, 0.6, 0, 0, 0,
            0.3, 0.6, 0, 0, 0,
            0.3, 0.6, 0, 0, 0,
            0, 0, 0, 1, 0
        ];
        var colorFlilter = new egret.ColorMatrixFilter(colorMatrix);
        btm.filters = [colorFlilter];
    }
    public static setNoneFlilter(btm: egret.Bitmap) {
        btm.filters = [];
    }
    public static setBlueFliter(img: egret.Bitmap) {
        return;
        var color: number = 0x33CCFF;        /// 光晕的颜色，十六进制，不包含透明度
        var alpha: number = 0.8;             /// 光晕的颜色透明度，是对 color 参数的透明度设定。有效值为 0.0 到 1.0。例如，0.8 设置透明度值为 80%。
        var blurX: number = 10;              /// 水平模糊量。有效值为 0 到 255.0（浮点）
        var blurY: number = 10;              /// 垂直模糊量。有效值为 0 到 255.0（浮点）
        var strength: number = 5;            /// 压印的强度，值越大，压印的颜色越深，而且发光与背景之间的对比度也越强。有效值为 0 到 255。暂未实现
        var quality: number = egret.BitmapFilterQuality.HIGH;        /// 应用滤镜的次数，建议用 BitmapFilterQuality 类的常量来体现
        var inner: boolean = false;            /// 指定发光是否为内侧发光，暂未实现
        var knockout: boolean = false;            /// 指定对象是否具有挖空效果，暂未实现
        var glowFilter: egret.GlowFilter = new egret.GlowFilter(color, alpha, blurX, blurY,
            strength, quality, inner, knockout);
        img.filters = [glowFilter];
    }
	/**
     * 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
     * Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
     */
    public static createBitmapByName(name: string): egret.Bitmap {
        var result: egret.Bitmap = new egret.Bitmap();
        var texture: egret.Texture = RES.getRes(name);
        result.texture = texture;
        return result;
    }
    public static createBTextureByName(name: string): egret.Texture {
        var texture: egret.Texture = RES.getRes(name);
        return texture;
    }
    public static random(a: number, b: number): number {
        return Math.round(a + Math.random() * b);
    }

    public static getWanNum(num: number): string {
        if (num >= 100000) {
            var wannum: number = Math.round(num / 10000);
            return wannum + "万";
        }
        return num + "";
    }
    public static getDouhaoNum(num: number): string {
        var str = String(num).replace(/(\d)(?=(\d\d\d)+$)/g, "$1,");
        return str;
    }
    public static getNormalNum(num: number): string {
        if (num >= 100000) {
            var wannum: number = num / 10000;
            return wannum + "万";
        }
        return num + "";
    }

    public static randomNum(): number {
        var i = ToolUtils.random(1, 36);
        if (i % 10 == 0)
            i = this.randomNum();
        //console.log("隧道什么啊？+"+i);
        return i;
    }
    public static jsCallEgret(sid: string, host: string, port: number): void {
        console.log("JS调用TS");
        // GameConfig.server = host;
        // GameConfig.port = port;
    }

    public static showRotaionTip(angle: number): void {
        console.log("JS调用TS");
        alert("请关闭重力感应，锁屏获得更好体验！");
        // if(angle == 0){

        // }
    }
    public static isDebug(): boolean {
        console.log("JS调用TS");
        return DEBUG;
    }
    public static getRealName(wordname: string) {
        var jie: string = "";
        if (wordname.length > 4) {
            jie = wordname.slice(0, 4) + "...";
            return jie;
        } else
            return wordname;
    }

    public static returnZhengfu(num: number): string {
        if (num > 0)
            return "+" + num;
        return num.toString();

    }
    public static strToObj(word1: string, data: any) {
        word1 = word1.replace(/{/g, '');
        word1 = word1.replace(/}/g, '');
        word1 = word1.replace(/"/g, '');
        word1 = word1.replace(/\s+/g, "");//删除所有空格;
        var arr: string[] = word1.split(';');
        for (var i = 0; i < arr.length; i++) {
            var arr2: string[] = arr[i].split('=');
            if (arr2[0] != "")
                data[arr2[0]] = arr2[1];
        }

    }
    public static get isNative() {
        // console.log("egret.MainContext.RUNTIME_NATIVE-----------------------------------------------------------------------"+egret.MainContext.RUNTIME_NATIVE);
        // console.log("egret.Capabilities.runtimeType-----------------------------------------------------------------------"+egret.Capabilities.runtimeType);
        if (egret.Capabilities.runtimeType == "web") {
            return false;
        } //值为 egret.MainContext.RUNTIME_HTML5或egret.MainContext.RUNTIME_NATIVE;
        return true;
    }

    public static addChild(pa: eui.Component, cd: egret.DisplayObject): void {
        var tw = egret.Tween.get(cd);
        cd.scaleX = 0;
        cd.scaleY = 0;
        pa.addChild(cd);
        tw.to({ scaleX: 1, scaleY: 1 }, 300, egret.Ease.backOut);
    }
    public static getTimeStr(game_over_timestamp: string) {
        var date = new Date(parseInt(game_over_timestamp));
        var hours: string = date.getHours() >= 10 ? date.getHours().toString() : "0" + date.getHours();
        var minutes: string = date.getMinutes() >= 10 ? date.getMinutes().toString() : "0" + date.getMinutes();
        var seconds: string = date.getSeconds() >= 10 ? date.getSeconds().toString() : "0" + date.getSeconds();

        return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + hours + ":" + minutes + ":" + seconds
    }
    //unicode为1个接收数据，串口收到的字符编码放在该数组中 
    public static UnicodeToUtf8(str: string) {
        str = str.replace(/\\U/g, "\\u");
        var str2 = eval("'" + str + "'");
        return str2;
    }

    public static getFiveName(str: string = "其实我也看出2") {
        if (str.length > 6) {
            var str: string = str.slice(0, 5) + "...";
            return str;

        }
        return str;
    }

    public static set localIP(value) {
        egret.localStorage.setItem("localIP", value.toString());

    }
    public static get localIP(): string {
        var b = egret.localStorage.getItem("localIP");
        return b;
    }

    public static set localPort(value) {
        egret.localStorage.setItem("localPort", value.toString());

    }
    public static get localPort(): string {
        var b = egret.localStorage.getItem("localPort");
        return b;
    }

}
